//
//  BankCardInfoCell.m
//  HHBroker
//
//  Created by He Wei on 10/18/15.
//  Copyright © 2015 harry. All rights reserved.
//

#import "BankCardInfoCell.h"
#import "UIViewAdditions.h"

@interface BankCardInfoCell ()

@property (nonatomic, strong) UIImageView *idCardImageView;
@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation BankCardInfoCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        [self addSubview:self.idCardImageView];
        [self addSubview:self.titleLabel];
        [self addSubview:self.infoLabel];
    }
    return self;
}

#pragma mark - Setter && Getter

- (UIImageView *)idCardImageView
{
    if (_idCardImageView == nil) {
        _idCardImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 13, 30, 30)];
        _idCardImageView.image = [UIImage imageNamed:@"img_bank_guangda"];
    }
    return _idCardImageView;

}

- (UILabel *)titleLabel
{
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.idCardImageView.right+15, 12, 140, 14)];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textColor = UIColorFromRGB(0x2d2d2d);
        _titleLabel.text = @"中国光大银行";
    }
    return _titleLabel;
}

- (UILabel *)infoLabel
{
    if (_infoLabel == nil) {
        _infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.idCardImageView.right+15, self.titleLabel.bottom+8, 140, 10)];
        _infoLabel.font = [UIFont systemFontOfSize:10];
        _infoLabel.textColor = UIColorFromRGB(0x999999);
    }
    return _infoLabel;
}

- (void)setBankCardNumber:(NSString *)bankCardNumber
{
    if (!bankCardNumber) {
        return;
    }
    if (bankCardNumber.length == 16) {
        NSString *trimString = [bankCardNumber substringFromIndex:12];
        NSString *secretString = [NSString stringWithFormat:@"**** **** ****%@", trimString];
        self.infoLabel.text = secretString;
    } else {
        self.infoLabel.text = bankCardNumber;
    }
}


@end
